package com.example.g3a1.notice

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.base.cons.ApiServer
import com.example.base.cons.entity.NoticeBeanItem
import com.example.base.cons.mvvm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class NoticeViewModel @Inject constructor(val apiServer: ApiServer) : BaseViewModel() {
    fun getNotive() : Flow<PagingData<NoticeBeanItem>>{
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            NoticeDataSource(apiServer)
        }).flow.cachedIn(viewModelScope)
    }
}